import {PlayerStatus} from "./constants";

export interface I_playerEnter {
    nickname:string;
    uid:number;
    sid:string;
    gold:number;
}

export class Player{
    nickname:string = "";
    uid:number = 0;
    sid:string = "";
    gold:number = 0;
    tableid:number = 0;
    seat:number = 0;
    status:number = 0;

    constructor(playerEnter:I_playerEnter) {
        this.nickname=playerEnter.nickname;
        this.uid=playerEnter.uid;
        this.sid=playerEnter.sid;
        this.gold=playerEnter.gold;
    }

    setStatus(status:number){
        this.status=status;
    }

    isPlaying():boolean{
        return this.status == PlayerStatus.PLAYING || this.status == PlayerStatus.DISCONNECTED;
    }

    isReady():boolean{
        return this.status == PlayerStatus.READY;
    }

    isDisconnected():boolean{
        return this.status == PlayerStatus.DISCONNECTED;
    }

    toJson(){
        return {
            nickname:this.nickname,
            uid:this.uid,
            gold:this.gold,
            seat:this.seat,
            status:this.status,
        }
    }
}